package com.etl.dataflow.common.response;

import java.util.HashMap;
import java.util.Map;

/**
 * @author dx
 */
public class R {

    private Map<String, Object> data = new HashMap<>();

    private int code;

    private String msg;

    public R(Code code) {
        this.code = code.code;
        this.msg = code.msg;
    }

    private R(Code code, Map<String, Object> data) {
        this.code = code.code;
        this.msg = code.msg;
        if (data != null) {
            this.data.putAll(data);
        }
    }

    public static R success() {
        return new R(Code.SUCCESS, null);
    }

    public static R error() {
        return new R(Code.ERROR, null);
    }

    public R put(String key, Object value) {
        data.put(key, value);
        return this;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public R setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public R setMsg(String msg) {
        this.msg = msg;
        return this;
    }
}
